<?php
    namespace app\admin\model;
    use think\Model;
    use think\Db;
    
//  model 类
class CouponModel extends Model
{
        

    // 新增 优惠券种类
    public static function couponAdd($amount, $discount, $expire, $available){
        $expire = 24 * 3600 * $expire;
        $res= Db('coupon')->insert(['amount'=> $amount,'discount'=>$discount,'expire'=>$expire,'available'=>$available]);
        return $res;
        
    }
       
       // 修改状态
    public static function updateCouponStatus($available = null, $coupon_id = null)
    {

        if (($available == null) || ($coupon_id == null)) {
            return false;
        }

        $now = Db::table('coupon')->field('available')->where('coupon_id', $coupon_id)->find();
            // echo Db::table('goods')->getLastSql();

        if (!empty($now) && ($now != $available)) {
            $res = Db::table('coupon')->where('coupon_id', $coupon_id)->update(['available' => $available]);

        } else {
            $res = false;

        }

        return $res;
    }
        

    // 删除
    public static function delCoupon($id){

        $res=Db('coupon')->where('coupon_id',$id)->update(['is_del'=>1]);

        return $res;
    }

    

}

